package com.hospital.hospital.controller;

import com.hospital.hospital.bean.Manager;
import com.hospital.hospital.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author xfm
 * @create 2021/9/3
 */
@Controller
@RequestMapping("/manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;
    @RequestMapping("/registUi")
    public String registUi(){
        return "regist";
    }
    @RequestMapping("/loginUi")
    public String loginUi(){
        return "login";
    }
    @RequestMapping("/welcomeUi")
    public String welcomeUi(){
        return "welcome";
    }
    @RequestMapping("/login")
    public String login(String mname, Model model,String password){
        try {
            Manager manager = managerService.login(mname);
            if(manager.getPassword().equals(password)){
                model.addAttribute("manager",manager);
                return "redirect:/manager/indexUi";
            }else {
                return "redirect:/manager/loginUi";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "redirect:/manager/loginUi";
        }
    }
    @RequestMapping("/regist")
    public String regist(Model model,Manager manager){
        try {
            managerService.regist(manager);
            return "redirect:/manager/loginUi";
        } catch (Exception e) {
            e.printStackTrace();
            return "redirect:/manager/registUi";
        }
    }
    @RequestMapping("/indexUi")
    public String indexUi(){
        return"index";
    }


}

